/**
 * 版权所有 (C), 2019-2019, XXX有限公司
 * 项目名：com.company.study.designpatterns.factory.simple
 * 文件名: GameFactory
 * 日期: 2019/6/15 9:41
 * 说明:
 */
package com.company.study.designpatterns.factory.simple;

import com.company.study.designpatterns.factory.Game;
import com.company.study.designpatterns.factory.GameType;
import com.company.study.designpatterns.factory.ShootGame;
import com.company.study.designpatterns.factory.TowerDefenceGame;

/**
 * 游戏工厂(单例：使用静态内部类实现)
 *
 * @author Anbang713
 * @create 2019/6/15
 */
public class GameFactory {

    private GameFactory() {
    }

    private static class SingletonHolder {
        private static final GameFactory INSTANCE = new GameFactory();
    }

    public static GameFactory getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public Game create(GameType type) {
        if (type == null) {
            return null;
        }
        if (GameType.shoot.equals(type)) {
            return new ShootGame();
        } else if (GameType.towerdefence.equals(type)) {
            return new TowerDefenceGame();
        }
        return null;
    }
}